package com.example.origin.spider.utils;

import com.example.origin.spider.dto.JkQuickSpiderAdvanceLoanReport;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.openqa.selenium.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Slf4j
@UtilityClass
public class ExtraUtil {


    private String filterCheckCode(String code) {

        String regEx = "[^0-9]";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(code);
        return m.replaceAll("").trim();
    }

    public boolean doesWebElementExist(WebDriver driver, String selector) {

        try {
            driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
            if (!driver.findElements(By.cssSelector(selector)).isEmpty()) {
                return true;
            } else {
                return false;
            }

        } catch (NoSuchElementException e) {
            return false;
        }
    }

    public List<JkQuickSpiderAdvanceLoanReport> getJkQuickSpiderAdvanceLoanReports(WebDriver driver) throws InterruptedException, ParseException {

        driver.findElement(By.id("646")).click();
        Thread.sleep(3 * 1000);
        driver.findElement(By.id("13073c56-16712888ba7-81d76f67e9fa75bc16134518e029baa9")).click();
        Thread.sleep(3 * 1000);
        driver.findElement(By.id("res13073c56-1671288960b-81d76f67e9fa75bc16134518e029baa9")).click();
        Thread.sleep(3 * 1000);
        driver.findElement(By.id("res13073c56-16712889da5-81d76f67e9fa75bc16134518e029baa9")).click();
        Thread.sleep(3 * 1000);
        driver.findElement(By.id("res13073c56-1671288a353-81d76f67e9fa75bc16134518e029baa9")).click();
        driver.findElement(By.id("res13073c56-1671288a353-81d76f67e9fa75bc16134518e029baa9")).click();
        Thread.sleep(10 * 1000);

        String url = driver.findElement(By.id("myframe")).getAttribute("src");
        Set<Cookie> cookies = driver.manage().getCookies();
        //获取登录的cookies
        String cookieStr = "";
        for (Cookie cookie : cookies) {
            cookieStr += cookie.getName() + "=" + cookie.getValue() + ";";
            driver.manage().addCookie(cookie);
        }
        log.info("--cookieStr==" + cookieStr);
        driver.manage().timeouts().implicitlyWait(300000000, TimeUnit.SECONDS);
        driver.get(url);
        Thread.sleep(10 * 1000);


        driver.findElement(By.cssSelector("#startDate > div > div.u-form-textbox-field > input")).clear();
        driver.findElement(By.cssSelector("#startDate > div > div.u-form-textbox-field > input")).sendKeys("2024-04-01");
        driver.findElement(By.cssSelector("#endDate > div > div.u-form-textbox-field > input")).clear();
        driver.findElement(By.cssSelector("#endDate > div > div.u-form-textbox-field > input")).sendKeys("2024-04-30");
        driver.findElement(By.cssSelector("#isReported > div > div.u-form-textbox-field > input")).click();
        driver.findElement(By.cssSelector("#unieap_form_ComboBoxPopup_0 > div.u-combobox-items-container > table > tbody > tr:nth-child(3) > td > span")).click();
        driver.findElement(By.cssSelector("#unieap_form_Button_0 > nobr > span.u-form-btn-txt")).click();
        Thread.sleep(5 * 1000);
        List<JkQuickSpiderAdvanceLoanReport> reportList = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String pageSizeStr = driver.findElement(By.cssSelector("#unieap_grid_view_toolbar_0 > div:nth-child(1) > table > tbody > tr > td:nth-child(4) > span")).getText();
        String pageSize = filterCheckCode(pageSizeStr);
        int pageNo = Integer.valueOf(pageSize);
        if (pageNo == 1) {
            List<WebElement> oneElements = new ArrayList<>();
            if (doesWebElementExist(driver, "#page-0 > div:nth-child(1) > table > tbody > tr > td > nobr")) {
                oneElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(1) > table > tbody > tr > td > nobr"));
            }
            List<WebElement> twoElements = new ArrayList<>();
            if (doesWebElementExist(driver, "#page-0 > div:nth-child(2) > table > tbody > tr > td > nobr")) {
                twoElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(2) > table > tbody > tr > td > nobr"));
            }
            List<WebElement> threeElements = new ArrayList<>();
            if (doesWebElementExist(driver, "#page-0 > div:nth-child(3) > table > tbody > tr > td > nobr")) {
                threeElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(3) > table > tbody > tr > td > nobr"));
            }
            List<WebElement> fourElements = new ArrayList<>();
            if (doesWebElementExist(driver, "#page-0 > div:nth-child(4) > table > tbody > tr > td > nobr")) {
                fourElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(4) > table > tbody > tr > td > nobr"));
            }
            List<WebElement> fiveElements = new ArrayList<>();
            if (doesWebElementExist(driver, "#page-0 > div:nth-child(5) > table > tbody > tr > td > nobr")) {
                fiveElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(5) > table > tbody > tr > td > nobr"));
            }
            List<WebElement> sixElements = new ArrayList<>();
            if (doesWebElementExist(driver, "#page-0 > div:nth-child(6) > table > tbody > tr > td > nobr")) {
                sixElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(6) > table > tbody > tr > td > nobr"));
            }
            List<WebElement> sevenElements = new ArrayList<>();
            if (doesWebElementExist(driver, "#page-0 > div:nth-child(7) > table > tbody > tr > td > nobr")) {
                sevenElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(7) > table > tbody > tr > td > nobr"));
            }
            List<WebElement> eightElements = new ArrayList<>();
            if (doesWebElementExist(driver, "#page-0 > div:nth-child(8) > table > tbody > tr > td > nobr")) {
                eightElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(8) > table > tbody > tr > td > nobr"));
            }
            List<WebElement> nineElements = new ArrayList<>();
            if (doesWebElementExist(driver, "#page-0 > div:nth-child(9) > table > tbody > tr > td > nobr")) {
                nineElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(9) > table > tbody > tr > td > nobr"));
            }
            List<WebElement> tenElements = new ArrayList<>();
            if (doesWebElementExist(driver, "#page-0 > div:nth-child(10) > table > tbody > tr > td > nobr")) {
                tenElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(10) > table > tbody > tr > td > nobr"));
            }
            List<WebElement> elevenElements = new ArrayList<>();
            if (doesWebElementExist(driver, "#page-0 > div:nth-child(11) > table > tbody > tr > td > nobr")) {
                elevenElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(11) > table > tbody > tr > td > nobr"));
            }
            List<WebElement> twelveElements = new ArrayList<>();
            if (doesWebElementExist(driver, "#page-0 > div:nth-child(12) > table > tbody > tr > td > nobr")) {
                twelveElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(12) > table > tbody > tr > td > nobr"));
            }
            List<WebElement> thirteenElements = new ArrayList<>();
            if (doesWebElementExist(driver, "#page-0 > div:nth-child(13) > table > tbody > tr > td > nobr")) {
                thirteenElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(13) > table > tbody > tr > td > nobr"));
            }
            List<WebElement> fourteenElements = new ArrayList<>();
            if (doesWebElementExist(driver, "#page-0 > div:nth-child(14) > table > tbody > tr > td > nobr")) {
                fourteenElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(14) > table > tbody > tr > td > nobr"));
            }
            List<WebElement> fiveteenElements = new ArrayList<>();
            if (doesWebElementExist(driver, "#page-0 > div:nth-child(15) > table > tbody > tr > td > nobr")) {
                fiveteenElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(15) > table > tbody > tr > td > nobr"));
            }
            if (CollectionUtils.isNotEmpty(oneElements)) {
                JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                String declarationNumber = oneElements.get(0).getText();
                String isPayment = oneElements.get(1).getText();
                String collectionCurrency = oneElements.get(2).getText();
                String collectionAmount = oneElements.get(3).getText();
                String collectionDateStr = oneElements.get(4).getText();
                String isAdvanceSales = oneElements.get(5).getText();
                String transactionPostscript = oneElements.get(6).getText();
                report.setCreateTime(fmt.parse(fmt.format(new Date())));
                report.setSpiderFrom("国家外汇管理局");
                report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                report.setDeclarationNumber(declarationNumber);
                report.setIsPayment(isPayment);
                report.setCollectionCurrency(collectionCurrency);
                report.setCollectionAmount(collectionAmount);
                report.setCollectionDate(sdf.parse(collectionDateStr));
                report.setIsAdvanceSales(isAdvanceSales);
                report.setTransactionPostscript(transactionPostscript);
                reportList.add(report);
            }
            if (CollectionUtils.isNotEmpty(twoElements)) {
                JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                String declarationNumber = twoElements.get(0).getText();
                String isPayment = twoElements.get(1).getText();
                String collectionCurrency = twoElements.get(2).getText();
                String collectionAmount = twoElements.get(3).getText();
                String collectionDateStr = twoElements.get(4).getText();
                String isAdvanceSales = twoElements.get(5).getText();
                String transactionPostscript = twoElements.get(6).getText();
                report.setCreateTime(fmt.parse(fmt.format(new Date())));
                report.setSpiderFrom("国家外汇管理局");
                report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                report.setDeclarationNumber(declarationNumber);
                report.setIsPayment(isPayment);
                report.setCollectionCurrency(collectionCurrency);
                report.setCollectionAmount(collectionAmount);
                report.setCollectionDate(sdf.parse(collectionDateStr));
                report.setIsAdvanceSales(isAdvanceSales);
                report.setTransactionPostscript(transactionPostscript);
                reportList.add(report);
            }
            if (CollectionUtils.isNotEmpty(threeElements)) {
                JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                String declarationNumber = threeElements.get(0).getText();
                String isPayment = threeElements.get(1).getText();
                String collectionCurrency = threeElements.get(2).getText();
                String collectionAmount = threeElements.get(3).getText();
                String collectionDateStr = threeElements.get(4).getText();
                String isAdvanceSales = threeElements.get(5).getText();
                String transactionPostscript = threeElements.get(6).getText();
                report.setCreateTime(fmt.parse(fmt.format(new Date())));
                report.setSpiderFrom("国家外汇管理局");
                report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                report.setDeclarationNumber(declarationNumber);
                report.setIsPayment(isPayment);
                report.setCollectionCurrency(collectionCurrency);
                report.setCollectionAmount(collectionAmount);
                report.setCollectionDate(sdf.parse(collectionDateStr));
                report.setIsAdvanceSales(isAdvanceSales);
                report.setTransactionPostscript(transactionPostscript);
                reportList.add(report);
            }
            if (CollectionUtils.isNotEmpty(fourElements)) {
                JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                String declarationNumber = fourElements.get(0).getText();
                String isPayment = fourElements.get(1).getText();
                String collectionCurrency = fourElements.get(2).getText();
                String collectionAmount = fourElements.get(3).getText();
                String collectionDateStr = fourElements.get(4).getText();
                String isAdvanceSales = fourElements.get(5).getText();
                String transactionPostscript = fourElements.get(6).getText();
                report.setCreateTime(fmt.parse(fmt.format(new Date())));
                report.setSpiderFrom("国家外汇管理局");
                report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                report.setDeclarationNumber(declarationNumber);
                report.setIsPayment(isPayment);
                report.setCollectionCurrency(collectionCurrency);
                report.setCollectionAmount(collectionAmount);
                report.setCollectionDate(sdf.parse(collectionDateStr));
                report.setIsAdvanceSales(isAdvanceSales);
                report.setTransactionPostscript(transactionPostscript);
                reportList.add(report);
            }
            if (CollectionUtils.isNotEmpty(fiveElements)) {
                JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                String declarationNumber = fiveElements.get(0).getText();
                String isPayment = fiveElements.get(1).getText();
                String collectionCurrency = fiveElements.get(2).getText();
                String collectionAmount = fiveElements.get(3).getText();
                String collectionDateStr = fiveElements.get(4).getText();
                String isAdvanceSales = fiveElements.get(5).getText();
                String transactionPostscript = fiveElements.get(6).getText();
                report.setCreateTime(fmt.parse(fmt.format(new Date())));
                report.setSpiderFrom("国家外汇管理局");
                report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                report.setDeclarationNumber(declarationNumber);
                report.setIsPayment(isPayment);
                report.setCollectionCurrency(collectionCurrency);
                report.setCollectionAmount(collectionAmount);
                report.setCollectionDate(sdf.parse(collectionDateStr));
                report.setIsAdvanceSales(isAdvanceSales);
                report.setTransactionPostscript(transactionPostscript);
                reportList.add(report);
            }
            if (CollectionUtils.isNotEmpty(sixElements)) {
                JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                String declarationNumber = sixElements.get(0).getText();
                String isPayment = sixElements.get(1).getText();
                String collectionCurrency = sixElements.get(2).getText();
                String collectionAmount = sixElements.get(3).getText();
                String collectionDateStr = sixElements.get(4).getText();
                String isAdvanceSales = sixElements.get(5).getText();
                String transactionPostscript = sixElements.get(6).getText();
                report.setCreateTime(fmt.parse(fmt.format(new Date())));
                report.setSpiderFrom("国家外汇管理局");
                report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                report.setDeclarationNumber(declarationNumber);
                report.setIsPayment(isPayment);
                report.setCollectionCurrency(collectionCurrency);
                report.setCollectionAmount(collectionAmount);
                report.setCollectionDate(sdf.parse(collectionDateStr));
                report.setIsAdvanceSales(isAdvanceSales);
                report.setTransactionPostscript(transactionPostscript);
                reportList.add(report);
            }
            if (CollectionUtils.isNotEmpty(sevenElements)) {
                JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                String declarationNumber = sevenElements.get(0).getText();
                String isPayment = sevenElements.get(1).getText();
                String collectionCurrency = sevenElements.get(2).getText();
                String collectionAmount = sevenElements.get(3).getText();
                String collectionDateStr = sevenElements.get(4).getText();
                String isAdvanceSales = sevenElements.get(5).getText();
                String transactionPostscript = sevenElements.get(6).getText();
                report.setCreateTime(fmt.parse(fmt.format(new Date())));
                report.setSpiderFrom("国家外汇管理局");
                report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                report.setDeclarationNumber(declarationNumber);
                report.setIsPayment(isPayment);
                report.setCollectionCurrency(collectionCurrency);
                report.setCollectionAmount(collectionAmount);
                report.setCollectionDate(sdf.parse(collectionDateStr));
                report.setIsAdvanceSales(isAdvanceSales);
                report.setTransactionPostscript(transactionPostscript);
                reportList.add(report);
            }
            if (CollectionUtils.isNotEmpty(eightElements)) {
                JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                String declarationNumber = eightElements.get(0).getText();
                String isPayment = eightElements.get(1).getText();
                String collectionCurrency = eightElements.get(2).getText();
                String collectionAmount = eightElements.get(3).getText();
                String collectionDateStr = eightElements.get(4).getText();
                String isAdvanceSales = eightElements.get(5).getText();
                String transactionPostscript = eightElements.get(6).getText();
                report.setCreateTime(fmt.parse(fmt.format(new Date())));
                report.setSpiderFrom("国家外汇管理局");
                report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                report.setDeclarationNumber(declarationNumber);
                report.setIsPayment(isPayment);
                report.setCollectionCurrency(collectionCurrency);
                report.setCollectionAmount(collectionAmount);
                report.setCollectionDate(sdf.parse(collectionDateStr));
                report.setIsAdvanceSales(isAdvanceSales);
                report.setTransactionPostscript(transactionPostscript);
                reportList.add(report);
            }
            if (CollectionUtils.isNotEmpty(nineElements)) {
                JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                String declarationNumber = nineElements.get(0).getText();
                String isPayment = nineElements.get(1).getText();
                String collectionCurrency = nineElements.get(2).getText();
                String collectionAmount = nineElements.get(3).getText();
                String collectionDateStr = nineElements.get(4).getText();
                String isAdvanceSales = nineElements.get(5).getText();
                String transactionPostscript = nineElements.get(6).getText();
                report.setCreateTime(fmt.parse(fmt.format(new Date())));
                report.setSpiderFrom("国家外汇管理局");
                report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                report.setDeclarationNumber(declarationNumber);
                report.setIsPayment(isPayment);
                report.setCollectionCurrency(collectionCurrency);
                report.setCollectionAmount(collectionAmount);
                report.setCollectionDate(sdf.parse(collectionDateStr));
                report.setIsAdvanceSales(isAdvanceSales);
                report.setTransactionPostscript(transactionPostscript);
                reportList.add(report);
            }
            if (CollectionUtils.isNotEmpty(tenElements)) {
                JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                String declarationNumber = tenElements.get(0).getText();
                String isPayment = tenElements.get(1).getText();
                String collectionCurrency = tenElements.get(2).getText();
                String collectionAmount = tenElements.get(3).getText();
                String collectionDateStr = tenElements.get(4).getText();
                String isAdvanceSales = tenElements.get(5).getText();
                String transactionPostscript = tenElements.get(6).getText();
                report.setCreateTime(fmt.parse(fmt.format(new Date())));
                report.setSpiderFrom("国家外汇管理局");
                report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                report.setDeclarationNumber(declarationNumber);
                report.setIsPayment(isPayment);
                report.setCollectionCurrency(collectionCurrency);
                report.setCollectionAmount(collectionAmount);
                report.setCollectionDate(sdf.parse(collectionDateStr));
                report.setIsAdvanceSales(isAdvanceSales);
                report.setTransactionPostscript(transactionPostscript);
                reportList.add(report);
            }
            if (CollectionUtils.isNotEmpty(elevenElements)) {
                JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                String declarationNumber = elevenElements.get(0).getText();
                String isPayment = elevenElements.get(1).getText();
                String collectionCurrency = elevenElements.get(2).getText();
                String collectionAmount = elevenElements.get(3).getText();
                String collectionDateStr = elevenElements.get(4).getText();
                String isAdvanceSales = elevenElements.get(5).getText();
                String transactionPostscript = elevenElements.get(6).getText();
                report.setCreateTime(fmt.parse(fmt.format(new Date())));
                report.setSpiderFrom("国家外汇管理局");
                report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                report.setDeclarationNumber(declarationNumber);
                report.setIsPayment(isPayment);
                report.setCollectionCurrency(collectionCurrency);
                report.setCollectionAmount(collectionAmount);
                report.setCollectionDate(sdf.parse(collectionDateStr));
                report.setIsAdvanceSales(isAdvanceSales);
                report.setTransactionPostscript(transactionPostscript);
                reportList.add(report);
            }
            if (CollectionUtils.isNotEmpty(twelveElements)) {
                JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                String declarationNumber = twelveElements.get(0).getText();
                String isPayment = twelveElements.get(1).getText();
                String collectionCurrency = twelveElements.get(2).getText();
                String collectionAmount = twelveElements.get(3).getText();
                String collectionDateStr = twelveElements.get(4).getText();
                String isAdvanceSales = twelveElements.get(5).getText();
                String transactionPostscript = twelveElements.get(6).getText();
                report.setCreateTime(fmt.parse(fmt.format(new Date())));
                report.setSpiderFrom("国家外汇管理局");
                report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                report.setDeclarationNumber(declarationNumber);
                report.setIsPayment(isPayment);
                report.setCollectionCurrency(collectionCurrency);
                report.setCollectionAmount(collectionAmount);
                report.setCollectionDate(sdf.parse(collectionDateStr));
                report.setIsAdvanceSales(isAdvanceSales);
                report.setTransactionPostscript(transactionPostscript);
                reportList.add(report);
            }
            if (CollectionUtils.isNotEmpty(thirteenElements)) {
                JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                String declarationNumber = thirteenElements.get(0).getText();
                String isPayment = thirteenElements.get(1).getText();
                String collectionCurrency = thirteenElements.get(2).getText();
                String collectionAmount = thirteenElements.get(3).getText();
                String collectionDateStr = thirteenElements.get(4).getText();
                String isAdvanceSales = thirteenElements.get(5).getText();
                String transactionPostscript = thirteenElements.get(6).getText();
                report.setCreateTime(fmt.parse(fmt.format(new Date())));
                report.setSpiderFrom("国家外汇管理局");
                report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                report.setDeclarationNumber(declarationNumber);
                report.setIsPayment(isPayment);
                report.setCollectionCurrency(collectionCurrency);
                report.setCollectionAmount(collectionAmount);
                report.setCollectionDate(sdf.parse(collectionDateStr));
                report.setIsAdvanceSales(isAdvanceSales);
                report.setTransactionPostscript(transactionPostscript);
                reportList.add(report);
            }
            if (CollectionUtils.isNotEmpty(fourteenElements)) {
                JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                String declarationNumber = fourteenElements.get(0).getText();
                String isPayment = fourteenElements.get(1).getText();
                String collectionCurrency = fourteenElements.get(2).getText();
                String collectionAmount = fourteenElements.get(3).getText();
                String collectionDateStr = fourteenElements.get(4).getText();
                String isAdvanceSales = fourteenElements.get(5).getText();
                String transactionPostscript = fourteenElements.get(6).getText();
                report.setCreateTime(fmt.parse(fmt.format(new Date())));
                report.setSpiderFrom("国家外汇管理局");
                report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                report.setDeclarationNumber(declarationNumber);
                report.setIsPayment(isPayment);
                report.setCollectionCurrency(collectionCurrency);
                report.setCollectionAmount(collectionAmount);
                report.setCollectionDate(sdf.parse(collectionDateStr));
                report.setIsAdvanceSales(isAdvanceSales);
                report.setTransactionPostscript(transactionPostscript);
                reportList.add(report);
            }

            if (CollectionUtils.isNotEmpty(fiveteenElements)) {
                JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                String declarationNumber = fiveteenElements.get(0).getText();
                String isPayment = fiveteenElements.get(1).getText();
                String collectionCurrency = fiveteenElements.get(2).getText();
                String collectionAmount = fiveteenElements.get(3).getText();
                String collectionDateStr = fiveteenElements.get(4).getText();
                String isAdvanceSales = fiveteenElements.get(5).getText();
                String transactionPostscript = fiveteenElements.get(6).getText();
                report.setCreateTime(fmt.parse(fmt.format(new Date())));
                report.setSpiderFrom("国家外汇管理局");
                report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                report.setDeclarationNumber(declarationNumber);
                report.setIsPayment(isPayment);
                report.setCollectionCurrency(collectionCurrency);
                report.setCollectionAmount(collectionAmount);
                report.setCollectionDate(sdf.parse(collectionDateStr));
                report.setIsAdvanceSales(isAdvanceSales);
                report.setTransactionPostscript(transactionPostscript);
                reportList.add(report);
            }

        } else if (pageNo > 1) {
            for (int j = 0; j < 1; j++) {
                List<WebElement> oneElements = new ArrayList<>();
                if (doesWebElementExist(driver, "#page-0 > div:nth-child(1) > table > tbody > tr > td > nobr")) {
                    oneElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(1) > table > tbody > tr > td > nobr"));
                }
                List<WebElement> twoElements = new ArrayList<>();
                if (doesWebElementExist(driver, "#page-0 > div:nth-child(2) > table > tbody > tr > td > nobr")) {
                    twoElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(2) > table > tbody > tr > td > nobr"));
                }
                List<WebElement> threeElements = new ArrayList<>();
                if (doesWebElementExist(driver, "#page-0 > div:nth-child(3) > table > tbody > tr > td > nobr")) {
                    threeElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(3) > table > tbody > tr > td > nobr"));
                }
                List<WebElement> fourElements = new ArrayList<>();
                if (doesWebElementExist(driver, "#page-0 > div:nth-child(4) > table > tbody > tr > td > nobr")) {
                    fourElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(4) > table > tbody > tr > td > nobr"));
                }
                List<WebElement> fiveElements = new ArrayList<>();
                if (doesWebElementExist(driver, "#page-0 > div:nth-child(5) > table > tbody > tr > td > nobr")) {
                    fiveElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(5) > table > tbody > tr > td > nobr"));
                }
                List<WebElement> sixElements = new ArrayList<>();
                if (doesWebElementExist(driver, "#page-0 > div:nth-child(6) > table > tbody > tr > td > nobr")) {
                    sixElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(6) > table > tbody > tr > td > nobr"));
                }
                List<WebElement> sevenElements = new ArrayList<>();
                if (doesWebElementExist(driver, "#page-0 > div:nth-child(7) > table > tbody > tr > td > nobr")) {
                    sevenElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(7) > table > tbody > tr > td > nobr"));
                }
                List<WebElement> eightElements = new ArrayList<>();
                if (doesWebElementExist(driver, "#page-0 > div:nth-child(8) > table > tbody > tr > td > nobr")) {
                    eightElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(8) > table > tbody > tr > td > nobr"));
                }
                List<WebElement> nineElements = new ArrayList<>();
                if (doesWebElementExist(driver, "#page-0 > div:nth-child(9) > table > tbody > tr > td > nobr")) {
                    nineElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(9) > table > tbody > tr > td > nobr"));
                }
                List<WebElement> tenElements = new ArrayList<>();
                if (doesWebElementExist(driver, "#page-0 > div:nth-child(10) > table > tbody > tr > td > nobr")) {
                    tenElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(10) > table > tbody > tr > td > nobr"));
                }
                List<WebElement> elevenElements = new ArrayList<>();
                if (doesWebElementExist(driver, "#page-0 > div:nth-child(11) > table > tbody > tr > td > nobr")) {
                    elevenElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(11) > table > tbody > tr > td > nobr"));
                }
                List<WebElement> twelveElements = new ArrayList<>();
                if (doesWebElementExist(driver, "#page-0 > div:nth-child(12) > table > tbody > tr > td > nobr")) {
                    twelveElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(12) > table > tbody > tr > td > nobr"));
                }
                List<WebElement> thirteenElements = new ArrayList<>();
                if (doesWebElementExist(driver, "#page-0 > div:nth-child(13) > table > tbody > tr > td > nobr")) {
                    thirteenElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(13) > table > tbody > tr > td > nobr"));
                }
                List<WebElement> fourteenElements = new ArrayList<>();
                if (doesWebElementExist(driver, "#page-0 > div:nth-child(14) > table > tbody > tr > td > nobr")) {
                    fourteenElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(14) > table > tbody > tr > td > nobr"));
                }
                List<WebElement> fiveteenElements = new ArrayList<>();
                if (doesWebElementExist(driver, "#page-0 > div:nth-child(15) > table > tbody > tr > td > nobr")) {
                    fiveteenElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(15) > table > tbody > tr > td > nobr"));
                }
                if (CollectionUtils.isNotEmpty(oneElements)) {
                    JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                    String declarationNumber = oneElements.get(0).getText();
                    String isPayment = oneElements.get(1).getText();
                    String collectionCurrency = oneElements.get(2).getText();
                    String collectionAmount = oneElements.get(3).getText();
                    String collectionDateStr = oneElements.get(4).getText();
                    String isAdvanceSales = oneElements.get(5).getText();
                    String transactionPostscript = oneElements.get(6).getText();
                    report.setCreateTime(fmt.parse(fmt.format(new Date())));
                    report.setSpiderFrom("国家外汇管理局");
                    report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                    report.setDeclarationNumber(declarationNumber);
                    report.setIsPayment(isPayment);
                    report.setCollectionCurrency(collectionCurrency);
                    report.setCollectionAmount(collectionAmount);
                    report.setCollectionDate(sdf.parse(collectionDateStr));
                    report.setIsAdvanceSales(isAdvanceSales);
                    report.setTransactionPostscript(transactionPostscript);
                    reportList.add(report);
                }
                if (CollectionUtils.isNotEmpty(twoElements)) {
                    JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                    String declarationNumber = twoElements.get(0).getText();
                    String isPayment = twoElements.get(1).getText();
                    String collectionCurrency = twoElements.get(2).getText();
                    String collectionAmount = twoElements.get(3).getText();
                    String collectionDateStr = twoElements.get(4).getText();
                    String isAdvanceSales = twoElements.get(5).getText();
                    String transactionPostscript = twoElements.get(6).getText();
                    report.setCreateTime(fmt.parse(fmt.format(new Date())));
                    report.setSpiderFrom("国家外汇管理局");
                    report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                    report.setDeclarationNumber(declarationNumber);
                    report.setIsPayment(isPayment);
                    report.setCollectionCurrency(collectionCurrency);
                    report.setCollectionAmount(collectionAmount);
                    report.setCollectionDate(sdf.parse(collectionDateStr));
                    report.setIsAdvanceSales(isAdvanceSales);
                    report.setTransactionPostscript(transactionPostscript);
                    reportList.add(report);
                }
                if (CollectionUtils.isNotEmpty(threeElements)) {
                    JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                    String declarationNumber = threeElements.get(0).getText();
                    String isPayment = threeElements.get(1).getText();
                    String collectionCurrency = threeElements.get(2).getText();
                    String collectionAmount = threeElements.get(3).getText();
                    String collectionDateStr = threeElements.get(4).getText();
                    String isAdvanceSales = threeElements.get(5).getText();
                    String transactionPostscript = threeElements.get(6).getText();
                    report.setCreateTime(fmt.parse(fmt.format(new Date())));
                    report.setSpiderFrom("国家外汇管理局");
                    report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                    report.setDeclarationNumber(declarationNumber);
                    report.setIsPayment(isPayment);
                    report.setCollectionCurrency(collectionCurrency);
                    report.setCollectionAmount(collectionAmount);
                    report.setCollectionDate(sdf.parse(collectionDateStr));
                    report.setIsAdvanceSales(isAdvanceSales);
                    report.setTransactionPostscript(transactionPostscript);
                    reportList.add(report);
                }
                if (CollectionUtils.isNotEmpty(fourElements)) {
                    JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                    String declarationNumber = fourElements.get(0).getText();
                    String isPayment = fourElements.get(1).getText();
                    String collectionCurrency = fourElements.get(2).getText();
                    String collectionAmount = fourElements.get(3).getText();
                    String collectionDateStr = fourElements.get(4).getText();
                    String isAdvanceSales = fourElements.get(5).getText();
                    String transactionPostscript = fourElements.get(6).getText();
                    report.setCreateTime(fmt.parse(fmt.format(new Date())));
                    report.setSpiderFrom("国家外汇管理局");
                    report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                    report.setDeclarationNumber(declarationNumber);
                    report.setIsPayment(isPayment);
                    report.setCollectionCurrency(collectionCurrency);
                    report.setCollectionAmount(collectionAmount);
                    report.setCollectionDate(sdf.parse(collectionDateStr));
                    report.setIsAdvanceSales(isAdvanceSales);
                    report.setTransactionPostscript(transactionPostscript);
                    reportList.add(report);
                }
                if (CollectionUtils.isNotEmpty(fiveElements)) {
                    JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                    String declarationNumber = fiveElements.get(0).getText();
                    String isPayment = fiveElements.get(1).getText();
                    String collectionCurrency = fiveElements.get(2).getText();
                    String collectionAmount = fiveElements.get(3).getText();
                    String collectionDateStr = fiveElements.get(4).getText();
                    String isAdvanceSales = fiveElements.get(5).getText();
                    String transactionPostscript = fiveElements.get(6).getText();
                    report.setCreateTime(fmt.parse(fmt.format(new Date())));
                    report.setSpiderFrom("国家外汇管理局");
                    report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                    report.setDeclarationNumber(declarationNumber);
                    report.setIsPayment(isPayment);
                    report.setCollectionCurrency(collectionCurrency);
                    report.setCollectionAmount(collectionAmount);
                    report.setCollectionDate(sdf.parse(collectionDateStr));
                    report.setIsAdvanceSales(isAdvanceSales);
                    report.setTransactionPostscript(transactionPostscript);
                    reportList.add(report);
                }
                if (CollectionUtils.isNotEmpty(sixElements)) {
                    JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                    String declarationNumber = sixElements.get(0).getText();
                    String isPayment = sixElements.get(1).getText();
                    String collectionCurrency = sixElements.get(2).getText();
                    String collectionAmount = sixElements.get(3).getText();
                    String collectionDateStr = sixElements.get(4).getText();
                    String isAdvanceSales = sixElements.get(5).getText();
                    String transactionPostscript = sixElements.get(6).getText();
                    report.setCreateTime(fmt.parse(fmt.format(new Date())));
                    report.setSpiderFrom("国家外汇管理局");
                    report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                    report.setDeclarationNumber(declarationNumber);
                    report.setIsPayment(isPayment);
                    report.setCollectionCurrency(collectionCurrency);
                    report.setCollectionAmount(collectionAmount);
                    report.setCollectionDate(sdf.parse(collectionDateStr));
                    report.setIsAdvanceSales(isAdvanceSales);
                    report.setTransactionPostscript(transactionPostscript);
                    reportList.add(report);
                }
                if (CollectionUtils.isNotEmpty(sevenElements)) {
                    JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                    String declarationNumber = sevenElements.get(0).getText();
                    String isPayment = sevenElements.get(1).getText();
                    String collectionCurrency = sevenElements.get(2).getText();
                    String collectionAmount = sevenElements.get(3).getText();
                    String collectionDateStr = sevenElements.get(4).getText();
                    String isAdvanceSales = sevenElements.get(5).getText();
                    String transactionPostscript = sevenElements.get(6).getText();
                    report.setCreateTime(fmt.parse(fmt.format(new Date())));
                    report.setSpiderFrom("国家外汇管理局");
                    report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                    report.setDeclarationNumber(declarationNumber);
                    report.setIsPayment(isPayment);
                    report.setCollectionCurrency(collectionCurrency);
                    report.setCollectionAmount(collectionAmount);
                    report.setCollectionDate(sdf.parse(collectionDateStr));
                    report.setIsAdvanceSales(isAdvanceSales);
                    report.setTransactionPostscript(transactionPostscript);
                    reportList.add(report);
                }
                if (CollectionUtils.isNotEmpty(eightElements)) {
                    JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                    String declarationNumber = eightElements.get(0).getText();
                    String isPayment = eightElements.get(1).getText();
                    String collectionCurrency = eightElements.get(2).getText();
                    String collectionAmount = eightElements.get(3).getText();
                    String collectionDateStr = eightElements.get(4).getText();
                    String isAdvanceSales = eightElements.get(5).getText();
                    String transactionPostscript = eightElements.get(6).getText();
                    report.setCreateTime(fmt.parse(fmt.format(new Date())));
                    report.setSpiderFrom("国家外汇管理局");
                    report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                    report.setDeclarationNumber(declarationNumber);
                    report.setIsPayment(isPayment);
                    report.setCollectionCurrency(collectionCurrency);
                    report.setCollectionAmount(collectionAmount);
                    report.setCollectionDate(sdf.parse(collectionDateStr));
                    report.setIsAdvanceSales(isAdvanceSales);
                    report.setTransactionPostscript(transactionPostscript);
                    reportList.add(report);
                }
                if (CollectionUtils.isNotEmpty(nineElements)) {
                    JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                    String declarationNumber = nineElements.get(0).getText();
                    String isPayment = nineElements.get(1).getText();
                    String collectionCurrency = nineElements.get(2).getText();
                    String collectionAmount = nineElements.get(3).getText();
                    String collectionDateStr = nineElements.get(4).getText();
                    String isAdvanceSales = nineElements.get(5).getText();
                    String transactionPostscript = nineElements.get(6).getText();
                    report.setCreateTime(fmt.parse(fmt.format(new Date())));
                    report.setSpiderFrom("国家外汇管理局");
                    report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                    report.setDeclarationNumber(declarationNumber);
                    report.setIsPayment(isPayment);
                    report.setCollectionCurrency(collectionCurrency);
                    report.setCollectionAmount(collectionAmount);
                    report.setCollectionDate(sdf.parse(collectionDateStr));
                    report.setIsAdvanceSales(isAdvanceSales);
                    report.setTransactionPostscript(transactionPostscript);
                    reportList.add(report);
                }
                if (CollectionUtils.isNotEmpty(tenElements)) {
                    JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                    String declarationNumber = tenElements.get(0).getText();
                    String isPayment = tenElements.get(1).getText();
                    String collectionCurrency = tenElements.get(2).getText();
                    String collectionAmount = tenElements.get(3).getText();
                    String collectionDateStr = tenElements.get(4).getText();
                    String isAdvanceSales = tenElements.get(5).getText();
                    String transactionPostscript = tenElements.get(6).getText();
                    report.setCreateTime(fmt.parse(fmt.format(new Date())));
                    report.setSpiderFrom("国家外汇管理局");
                    report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                    report.setDeclarationNumber(declarationNumber);
                    report.setIsPayment(isPayment);
                    report.setCollectionCurrency(collectionCurrency);
                    report.setCollectionAmount(collectionAmount);
                    report.setCollectionDate(sdf.parse(collectionDateStr));
                    report.setIsAdvanceSales(isAdvanceSales);
                    report.setTransactionPostscript(transactionPostscript);
                    reportList.add(report);
                }
                if (CollectionUtils.isNotEmpty(elevenElements)) {
                    JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                    String declarationNumber = elevenElements.get(0).getText();
                    String isPayment = elevenElements.get(1).getText();
                    String collectionCurrency = elevenElements.get(2).getText();
                    String collectionAmount = elevenElements.get(3).getText();
                    String collectionDateStr = elevenElements.get(4).getText();
                    String isAdvanceSales = elevenElements.get(5).getText();
                    String transactionPostscript = elevenElements.get(6).getText();
                    report.setCreateTime(fmt.parse(fmt.format(new Date())));
                    report.setSpiderFrom("国家外汇管理局");
                    report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                    report.setDeclarationNumber(declarationNumber);
                    report.setIsPayment(isPayment);
                    report.setCollectionCurrency(collectionCurrency);
                    report.setCollectionAmount(collectionAmount);
                    report.setCollectionDate(sdf.parse(collectionDateStr));
                    report.setIsAdvanceSales(isAdvanceSales);
                    report.setTransactionPostscript(transactionPostscript);
                    reportList.add(report);
                }
                if (CollectionUtils.isNotEmpty(twelveElements)) {
                    JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                    String declarationNumber = twelveElements.get(0).getText();
                    String isPayment = twelveElements.get(1).getText();
                    String collectionCurrency = twelveElements.get(2).getText();
                    String collectionAmount = twelveElements.get(3).getText();
                    String collectionDateStr = twelveElements.get(4).getText();
                    String isAdvanceSales = twelveElements.get(5).getText();
                    String transactionPostscript = twelveElements.get(6).getText();
                    report.setCreateTime(fmt.parse(fmt.format(new Date())));
                    report.setSpiderFrom("国家外汇管理局");
                    report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                    report.setDeclarationNumber(declarationNumber);
                    report.setIsPayment(isPayment);
                    report.setCollectionCurrency(collectionCurrency);
                    report.setCollectionAmount(collectionAmount);
                    report.setCollectionDate(sdf.parse(collectionDateStr));
                    report.setIsAdvanceSales(isAdvanceSales);
                    report.setTransactionPostscript(transactionPostscript);
                    reportList.add(report);
                }
                if (CollectionUtils.isNotEmpty(thirteenElements)) {
                    JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                    String declarationNumber = thirteenElements.get(0).getText();
                    String isPayment = thirteenElements.get(1).getText();
                    String collectionCurrency = thirteenElements.get(2).getText();
                    String collectionAmount = thirteenElements.get(3).getText();
                    String collectionDateStr = thirteenElements.get(4).getText();
                    String isAdvanceSales = thirteenElements.get(5).getText();
                    String transactionPostscript = thirteenElements.get(6).getText();
                    report.setCreateTime(fmt.parse(fmt.format(new Date())));
                    report.setSpiderFrom("国家外汇管理局");
                    report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                    report.setDeclarationNumber(declarationNumber);
                    report.setIsPayment(isPayment);
                    report.setCollectionCurrency(collectionCurrency);
                    report.setCollectionAmount(collectionAmount);
                    report.setCollectionDate(sdf.parse(collectionDateStr));
                    report.setIsAdvanceSales(isAdvanceSales);
                    report.setTransactionPostscript(transactionPostscript);
                    reportList.add(report);
                }
                if (CollectionUtils.isNotEmpty(fourteenElements)) {
                    JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                    String declarationNumber = fourteenElements.get(0).getText();
                    String isPayment = fourteenElements.get(1).getText();
                    String collectionCurrency = fourteenElements.get(2).getText();
                    String collectionAmount = fourteenElements.get(3).getText();
                    String collectionDateStr = fourteenElements.get(4).getText();
                    String isAdvanceSales = fourteenElements.get(5).getText();
                    String transactionPostscript = fourteenElements.get(6).getText();
                    report.setCreateTime(fmt.parse(fmt.format(new Date())));
                    report.setSpiderFrom("国家外汇管理局");
                    report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                    report.setDeclarationNumber(declarationNumber);
                    report.setIsPayment(isPayment);
                    report.setCollectionCurrency(collectionCurrency);
                    report.setCollectionAmount(collectionAmount);
                    report.setCollectionDate(sdf.parse(collectionDateStr));
                    report.setIsAdvanceSales(isAdvanceSales);
                    report.setTransactionPostscript(transactionPostscript);
                    reportList.add(report);
                }

                if (CollectionUtils.isNotEmpty(fiveteenElements)) {
                    JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                    String declarationNumber = fiveteenElements.get(0).getText();
                    String isPayment = fiveteenElements.get(1).getText();
                    String collectionCurrency = fiveteenElements.get(2).getText();
                    String collectionAmount = fiveteenElements.get(3).getText();
                    String collectionDateStr = fiveteenElements.get(4).getText();
                    String isAdvanceSales = fiveteenElements.get(5).getText();
                    String transactionPostscript = fiveteenElements.get(6).getText();
                    report.setCreateTime(fmt.parse(fmt.format(new Date())));
                    report.setSpiderFrom("国家外汇管理局");
                    report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                    report.setDeclarationNumber(declarationNumber);
                    report.setIsPayment(isPayment);
                    report.setCollectionCurrency(collectionCurrency);
                    report.setCollectionAmount(collectionAmount);
                    report.setCollectionDate(sdf.parse(collectionDateStr));
                    report.setIsAdvanceSales(isAdvanceSales);
                    report.setTransactionPostscript(transactionPostscript);
                    reportList.add(report);
                }
            }

            for (int i = 0; i < pageNo + 3; i++) {

                driver.findElement(By.cssSelector("#unieap_grid_view_toolbar_0 > div:nth-child(1) > table > tbody > tr > td:nth-child(5) > span")).click();
                Thread.sleep(10 * 1000);
                List<WebElement> oneElements = new ArrayList<>();
                if (doesWebElementExist(driver, "#page-0 > div:nth-child(1) > table > tbody > tr > td > nobr")) {
                    oneElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(1) > table > tbody > tr > td > nobr"));
                }
                List<WebElement> twoElements = new ArrayList<>();
                if (doesWebElementExist(driver, "#page-0 > div:nth-child(2) > table > tbody > tr > td > nobr")) {
                    twoElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(2) > table > tbody > tr > td > nobr"));
                }
                List<WebElement> threeElements = new ArrayList<>();
                if (doesWebElementExist(driver, "#page-0 > div:nth-child(3) > table > tbody > tr > td > nobr")) {
                    threeElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(3) > table > tbody > tr > td > nobr"));
                }
                List<WebElement> fourElements = new ArrayList<>();
                if (doesWebElementExist(driver, "#page-0 > div:nth-child(4) > table > tbody > tr > td > nobr")) {
                    fourElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(4) > table > tbody > tr > td > nobr"));
                }
                List<WebElement> fiveElements = new ArrayList<>();
                if (doesWebElementExist(driver, "#page-0 > div:nth-child(5) > table > tbody > tr > td > nobr")) {
                    fiveElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(5) > table > tbody > tr > td > nobr"));
                }
                List<WebElement> sixElements = new ArrayList<>();
                if (doesWebElementExist(driver, "#page-0 > div:nth-child(6) > table > tbody > tr > td > nobr")) {
                    sixElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(6) > table > tbody > tr > td > nobr"));
                }
                List<WebElement> sevenElements = new ArrayList<>();
                if (doesWebElementExist(driver, "#page-0 > div:nth-child(7) > table > tbody > tr > td > nobr")) {
                    sevenElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(7) > table > tbody > tr > td > nobr"));
                }
                List<WebElement> eightElements = new ArrayList<>();
                if (doesWebElementExist(driver, "#page-0 > div:nth-child(8) > table > tbody > tr > td > nobr")) {
                    eightElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(8) > table > tbody > tr > td > nobr"));
                }
                List<WebElement> nineElements = new ArrayList<>();
                if (doesWebElementExist(driver, "#page-0 > div:nth-child(9) > table > tbody > tr > td > nobr")) {
                    nineElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(9) > table > tbody > tr > td > nobr"));
                }
                List<WebElement> tenElements = new ArrayList<>();
                if (doesWebElementExist(driver, "#page-0 > div:nth-child(10) > table > tbody > tr > td > nobr")) {
                    tenElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(10) > table > tbody > tr > td > nobr"));
                }
                List<WebElement> elevenElements = new ArrayList<>();
                if (doesWebElementExist(driver, "#page-0 > div:nth-child(11) > table > tbody > tr > td > nobr")) {
                    elevenElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(11) > table > tbody > tr > td > nobr"));
                }
                List<WebElement> twelveElements = new ArrayList<>();
                if (doesWebElementExist(driver, "#page-0 > div:nth-child(12) > table > tbody > tr > td > nobr")) {
                    twelveElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(12) > table > tbody > tr > td > nobr"));
                }
                List<WebElement> thirteenElements = new ArrayList<>();
                if (doesWebElementExist(driver, "#page-0 > div:nth-child(13) > table > tbody > tr > td > nobr")) {
                    thirteenElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(13) > table > tbody > tr > td > nobr"));
                }
                List<WebElement> fourteenElements = new ArrayList<>();
                if (doesWebElementExist(driver, "#page-0 > div:nth-child(14) > table > tbody > tr > td > nobr")) {
                    fourteenElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(14) > table > tbody > tr > td > nobr"));
                }
                List<WebElement> fiveteenElements = new ArrayList<>();
                if (doesWebElementExist(driver, "#page-0 > div:nth-child(15) > table > tbody > tr > td > nobr")) {
                    fiveteenElements = driver.findElements(By.cssSelector("#page-0 > div:nth-child(15) > table > tbody > tr > td > nobr"));
                }

                if (CollectionUtils.isNotEmpty(oneElements)) {
                    JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                    String declarationNumber = oneElements.get(0).getText();
                    String isPayment = oneElements.get(1).getText();
                    String collectionCurrency = oneElements.get(2).getText();
                    String collectionAmount = oneElements.get(3).getText();
                    String collectionDateStr = oneElements.get(4).getText();
                    String isAdvanceSales = oneElements.get(5).getText();
                    String transactionPostscript = oneElements.get(6).getText();
                    report.setCreateTime(fmt.parse(fmt.format(new Date())));
                    report.setSpiderFrom("国家外汇管理局");
                    report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                    report.setDeclarationNumber(declarationNumber);
                    report.setIsPayment(isPayment);
                    report.setCollectionCurrency(collectionCurrency);
                    report.setCollectionAmount(collectionAmount);
                    report.setCollectionDate(sdf.parse(collectionDateStr));
                    report.setIsAdvanceSales(isAdvanceSales);
                    report.setTransactionPostscript(transactionPostscript);
                    reportList.add(report);
                }
                if (CollectionUtils.isNotEmpty(twoElements)) {
                    JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                    String declarationNumber = twoElements.get(0).getText();
                    String isPayment = twoElements.get(1).getText();
                    String collectionCurrency = twoElements.get(2).getText();
                    String collectionAmount = twoElements.get(3).getText();
                    String collectionDateStr = twoElements.get(4).getText();
                    String isAdvanceSales = twoElements.get(5).getText();
                    String transactionPostscript = twoElements.get(6).getText();
                    report.setCreateTime(fmt.parse(fmt.format(new Date())));
                    report.setSpiderFrom("国家外汇管理局");
                    report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                    report.setDeclarationNumber(declarationNumber);
                    report.setIsPayment(isPayment);
                    report.setCollectionCurrency(collectionCurrency);
                    report.setCollectionAmount(collectionAmount);
                    report.setCollectionDate(sdf.parse(collectionDateStr));
                    report.setIsAdvanceSales(isAdvanceSales);
                    report.setTransactionPostscript(transactionPostscript);
                    reportList.add(report);
                }
                if (CollectionUtils.isNotEmpty(threeElements)) {
                    JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                    String declarationNumber = threeElements.get(0).getText();
                    String isPayment = threeElements.get(1).getText();
                    String collectionCurrency = threeElements.get(2).getText();
                    String collectionAmount = threeElements.get(3).getText();
                    String collectionDateStr = threeElements.get(4).getText();
                    String isAdvanceSales = threeElements.get(5).getText();
                    String transactionPostscript = threeElements.get(6).getText();
                    report.setCreateTime(fmt.parse(fmt.format(new Date())));
                    report.setSpiderFrom("国家外汇管理局");
                    report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                    report.setDeclarationNumber(declarationNumber);
                    report.setIsPayment(isPayment);
                    report.setCollectionCurrency(collectionCurrency);
                    report.setCollectionAmount(collectionAmount);
                    report.setCollectionDate(sdf.parse(collectionDateStr));
                    report.setIsAdvanceSales(isAdvanceSales);
                    report.setTransactionPostscript(transactionPostscript);
                    reportList.add(report);
                }
                if (CollectionUtils.isNotEmpty(fourElements)) {
                    JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                    String declarationNumber = fourElements.get(0).getText();
                    String isPayment = fourElements.get(1).getText();
                    String collectionCurrency = fourElements.get(2).getText();
                    String collectionAmount = fourElements.get(3).getText();
                    String collectionDateStr = fourElements.get(4).getText();
                    String isAdvanceSales = fourElements.get(5).getText();
                    String transactionPostscript = fourElements.get(6).getText();
                    report.setCreateTime(fmt.parse(fmt.format(new Date())));
                    report.setSpiderFrom("国家外汇管理局");
                    report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                    report.setDeclarationNumber(declarationNumber);
                    report.setIsPayment(isPayment);
                    report.setCollectionCurrency(collectionCurrency);
                    report.setCollectionAmount(collectionAmount);
                    report.setCollectionDate(sdf.parse(collectionDateStr));
                    report.setIsAdvanceSales(isAdvanceSales);
                    report.setTransactionPostscript(transactionPostscript);
                    reportList.add(report);
                }
                if (CollectionUtils.isNotEmpty(fiveElements)) {
                    JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                    String declarationNumber = fiveElements.get(0).getText();
                    String isPayment = fiveElements.get(1).getText();
                    String collectionCurrency = fiveElements.get(2).getText();
                    String collectionAmount = fiveElements.get(3).getText();
                    String collectionDateStr = fiveElements.get(4).getText();
                    String isAdvanceSales = fiveElements.get(5).getText();
                    String transactionPostscript = fiveElements.get(6).getText();
                    report.setCreateTime(fmt.parse(fmt.format(new Date())));
                    report.setSpiderFrom("国家外汇管理局");
                    report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                    report.setDeclarationNumber(declarationNumber);
                    report.setIsPayment(isPayment);
                    report.setCollectionCurrency(collectionCurrency);
                    report.setCollectionAmount(collectionAmount);
                    report.setCollectionDate(sdf.parse(collectionDateStr));
                    report.setIsAdvanceSales(isAdvanceSales);
                    report.setTransactionPostscript(transactionPostscript);
                    reportList.add(report);
                }
                if (CollectionUtils.isNotEmpty(sixElements)) {
                    JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                    String declarationNumber = sixElements.get(0).getText();
                    String isPayment = sixElements.get(1).getText();
                    String collectionCurrency = sixElements.get(2).getText();
                    String collectionAmount = sixElements.get(3).getText();
                    String collectionDateStr = sixElements.get(4).getText();
                    String isAdvanceSales = sixElements.get(5).getText();
                    String transactionPostscript = sixElements.get(6).getText();
                    report.setCreateTime(fmt.parse(fmt.format(new Date())));
                    report.setSpiderFrom("国家外汇管理局");
                    report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                    report.setDeclarationNumber(declarationNumber);
                    report.setIsPayment(isPayment);
                    report.setCollectionCurrency(collectionCurrency);
                    report.setCollectionAmount(collectionAmount);
                    report.setCollectionDate(sdf.parse(collectionDateStr));
                    report.setIsAdvanceSales(isAdvanceSales);
                    report.setTransactionPostscript(transactionPostscript);
                    reportList.add(report);
                }
                if (CollectionUtils.isNotEmpty(sevenElements)) {
                    JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                    String declarationNumber = sevenElements.get(0).getText();
                    String isPayment = sevenElements.get(1).getText();
                    String collectionCurrency = sevenElements.get(2).getText();
                    String collectionAmount = sevenElements.get(3).getText();
                    String collectionDateStr = sevenElements.get(4).getText();
                    String isAdvanceSales = sevenElements.get(5).getText();
                    String transactionPostscript = sevenElements.get(6).getText();
                    report.setCreateTime(fmt.parse(fmt.format(new Date())));
                    report.setSpiderFrom("国家外汇管理局");
                    report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                    report.setDeclarationNumber(declarationNumber);
                    report.setIsPayment(isPayment);
                    report.setCollectionCurrency(collectionCurrency);
                    report.setCollectionAmount(collectionAmount);
                    report.setCollectionDate(sdf.parse(collectionDateStr));
                    report.setIsAdvanceSales(isAdvanceSales);
                    report.setTransactionPostscript(transactionPostscript);
                    reportList.add(report);
                }
                if (CollectionUtils.isNotEmpty(eightElements)) {
                    JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                    String declarationNumber = eightElements.get(0).getText();
                    String isPayment = eightElements.get(1).getText();
                    String collectionCurrency = eightElements.get(2).getText();
                    String collectionAmount = eightElements.get(3).getText();
                    String collectionDateStr = eightElements.get(4).getText();
                    String isAdvanceSales = eightElements.get(5).getText();
                    String transactionPostscript = eightElements.get(6).getText();
                    report.setCreateTime(fmt.parse(fmt.format(new Date())));
                    report.setSpiderFrom("国家外汇管理局");
                    report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                    report.setDeclarationNumber(declarationNumber);
                    report.setIsPayment(isPayment);
                    report.setCollectionCurrency(collectionCurrency);
                    report.setCollectionAmount(collectionAmount);
                    report.setCollectionDate(sdf.parse(collectionDateStr));
                    report.setIsAdvanceSales(isAdvanceSales);
                    report.setTransactionPostscript(transactionPostscript);
                    reportList.add(report);
                }
                if (CollectionUtils.isNotEmpty(nineElements)) {
                    JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                    String declarationNumber = nineElements.get(0).getText();
                    String isPayment = nineElements.get(1).getText();
                    String collectionCurrency = nineElements.get(2).getText();
                    String collectionAmount = nineElements.get(3).getText();
                    String collectionDateStr = nineElements.get(4).getText();
                    String isAdvanceSales = nineElements.get(5).getText();
                    String transactionPostscript = nineElements.get(6).getText();
                    report.setCreateTime(fmt.parse(fmt.format(new Date())));
                    report.setSpiderFrom("国家外汇管理局");
                    report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                    report.setDeclarationNumber(declarationNumber);
                    report.setIsPayment(isPayment);
                    report.setCollectionCurrency(collectionCurrency);
                    report.setCollectionAmount(collectionAmount);
                    report.setCollectionDate(sdf.parse(collectionDateStr));
                    report.setIsAdvanceSales(isAdvanceSales);
                    report.setTransactionPostscript(transactionPostscript);
                    reportList.add(report);
                }
                if (CollectionUtils.isNotEmpty(tenElements)) {
                    JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                    String declarationNumber = tenElements.get(0).getText();
                    String isPayment = tenElements.get(1).getText();
                    String collectionCurrency = tenElements.get(2).getText();
                    String collectionAmount = tenElements.get(3).getText();
                    String collectionDateStr = tenElements.get(4).getText();
                    String isAdvanceSales = tenElements.get(5).getText();
                    String transactionPostscript = tenElements.get(6).getText();
                    report.setCreateTime(fmt.parse(fmt.format(new Date())));
                    report.setSpiderFrom("国家外汇管理局");
                    report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                    report.setDeclarationNumber(declarationNumber);
                    report.setIsPayment(isPayment);
                    report.setCollectionCurrency(collectionCurrency);
                    report.setCollectionAmount(collectionAmount);
                    report.setCollectionDate(sdf.parse(collectionDateStr));
                    report.setIsAdvanceSales(isAdvanceSales);
                    report.setTransactionPostscript(transactionPostscript);
                    reportList.add(report);
                }
                if (CollectionUtils.isNotEmpty(elevenElements)) {
                    JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                    String declarationNumber = elevenElements.get(0).getText();
                    String isPayment = elevenElements.get(1).getText();
                    String collectionCurrency = elevenElements.get(2).getText();
                    String collectionAmount = elevenElements.get(3).getText();
                    String collectionDateStr = elevenElements.get(4).getText();
                    String isAdvanceSales = elevenElements.get(5).getText();
                    String transactionPostscript = elevenElements.get(6).getText();
                    report.setCreateTime(fmt.parse(fmt.format(new Date())));
                    report.setSpiderFrom("国家外汇管理局");
                    report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                    report.setDeclarationNumber(declarationNumber);
                    report.setIsPayment(isPayment);
                    report.setCollectionCurrency(collectionCurrency);
                    report.setCollectionAmount(collectionAmount);
                    report.setCollectionDate(sdf.parse(collectionDateStr));
                    report.setIsAdvanceSales(isAdvanceSales);
                    report.setTransactionPostscript(transactionPostscript);
                    reportList.add(report);
                }
                if (CollectionUtils.isNotEmpty(twelveElements)) {
                    JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                    String declarationNumber = twelveElements.get(0).getText();
                    String isPayment = twelveElements.get(1).getText();
                    String collectionCurrency = twelveElements.get(2).getText();
                    String collectionAmount = twelveElements.get(3).getText();
                    String collectionDateStr = twelveElements.get(4).getText();
                    String isAdvanceSales = twelveElements.get(5).getText();
                    String transactionPostscript = twelveElements.get(6).getText();
                    report.setCreateTime(fmt.parse(fmt.format(new Date())));
                    report.setSpiderFrom("国家外汇管理局");
                    report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                    report.setDeclarationNumber(declarationNumber);
                    report.setIsPayment(isPayment);
                    report.setCollectionCurrency(collectionCurrency);
                    report.setCollectionAmount(collectionAmount);
                    report.setCollectionDate(sdf.parse(collectionDateStr));
                    report.setIsAdvanceSales(isAdvanceSales);
                    report.setTransactionPostscript(transactionPostscript);
                    reportList.add(report);
                }
                if (CollectionUtils.isNotEmpty(thirteenElements)) {
                    JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                    String declarationNumber = thirteenElements.get(0).getText();
                    String isPayment = thirteenElements.get(1).getText();
                    String collectionCurrency = thirteenElements.get(2).getText();
                    String collectionAmount = thirteenElements.get(3).getText();
                    String collectionDateStr = thirteenElements.get(4).getText();
                    String isAdvanceSales = thirteenElements.get(5).getText();
                    String transactionPostscript = thirteenElements.get(6).getText();
                    report.setCreateTime(fmt.parse(fmt.format(new Date())));
                    report.setSpiderFrom("国家外汇管理局");
                    report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                    report.setDeclarationNumber(declarationNumber);
                    report.setIsPayment(isPayment);
                    report.setCollectionCurrency(collectionCurrency);
                    report.setCollectionAmount(collectionAmount);
                    report.setCollectionDate(sdf.parse(collectionDateStr));
                    report.setIsAdvanceSales(isAdvanceSales);
                    report.setTransactionPostscript(transactionPostscript);
                    reportList.add(report);
                }
                if (CollectionUtils.isNotEmpty(fourteenElements)) {
                    JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                    String declarationNumber = fourteenElements.get(0).getText();
                    String isPayment = fourteenElements.get(1).getText();
                    String collectionCurrency = fourteenElements.get(2).getText();
                    String collectionAmount = fourteenElements.get(3).getText();
                    String collectionDateStr = fourteenElements.get(4).getText();
                    String isAdvanceSales = fourteenElements.get(5).getText();
                    String transactionPostscript = fourteenElements.get(6).getText();
                    report.setCreateTime(fmt.parse(fmt.format(new Date())));
                    report.setSpiderFrom("国家外汇管理局");
                    report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                    report.setDeclarationNumber(declarationNumber);
                    report.setIsPayment(isPayment);
                    report.setCollectionCurrency(collectionCurrency);
                    report.setCollectionAmount(collectionAmount);
                    report.setCollectionDate(sdf.parse(collectionDateStr));
                    report.setIsAdvanceSales(isAdvanceSales);
                    report.setTransactionPostscript(transactionPostscript);
                    reportList.add(report);
                }

                if (CollectionUtils.isNotEmpty(fiveteenElements)) {
                    JkQuickSpiderAdvanceLoanReport report = new JkQuickSpiderAdvanceLoanReport();
                    String declarationNumber = fiveteenElements.get(0).getText();
                    String isPayment = fiveteenElements.get(1).getText();
                    String collectionCurrency = fiveteenElements.get(2).getText();
                    String collectionAmount = fiveteenElements.get(3).getText();
                    String collectionDateStr = fiveteenElements.get(4).getText();
                    String isAdvanceSales = fiveteenElements.get(5).getText();
                    String transactionPostscript = fiveteenElements.get(6).getText();
                    report.setCreateTime(fmt.parse(fmt.format(new Date())));
                    report.setSpiderFrom("国家外汇管理局");
                    report.setSpiderTime(fmt.parse(fmt.format(new Date())));
                    report.setDeclarationNumber(declarationNumber);
                    report.setIsPayment(isPayment);
                    report.setCollectionCurrency(collectionCurrency);
                    report.setCollectionAmount(collectionAmount);
                    report.setCollectionDate(sdf.parse(collectionDateStr));
                    report.setIsAdvanceSales(isAdvanceSales);
                    report.setTransactionPostscript(transactionPostscript);
                    reportList.add(report);
                }
            }
        }
        return reportList;
    }

}
